/**
 * Copyright 2009 University of Washington This code is released under the GPL version 3 - with a copy of the license
 * included
 * 
 * @author Maya Hao Li
 */
package seedpod.webapp.view.htmlwidget;

public class TableCell extends GenericHtmlWidget {
	private String	_cellContent;
	private boolean	_isNoWrap	= false;
	private int		_colspan	= 0;
	private String	_align		= "left";
	private boolean	_isHeader	= false;
	private String	_js			= "";

	public TableCell(String content) {
		_cellContent = content;
	}

	public void appendCellContent( String add ) {
		_cellContent += add;
	}

	public boolean isHeader() {
		return _isHeader;
	}

	@Override
	public String render() {
		StringBuffer td = new StringBuffer();
		td.append( _isHeader ? "<th " : "<td " );
		td.append( _widgetID != null ? " id=\"" + _widgetID + "\" " : "" );
		td.append( ATT( "class", _cssClass ) );
		td.append( _isNoWrap ? " nowrap " : "" );
		td.append( _colspan > 0 ? ATT( "colspan", _colspan ) : "" );
		td.append( ATT( "align", _align ) );
		td.append( _js );
		td.append( ">" );
		if ( _cellContent != null ) td.append( _cellContent.toString() );
		td.append( _isHeader ? "</th>" : "</td>" );
		return td.toString();
	}

	public void setAlignment( String align ) {
		_align = align;
	}

	public void setColSpan( int cs ) {
		_colspan = cs;
	}

	public void setIsHeader( boolean isHeader ) {
		_isHeader = isHeader;
	}

	public void setJScript( String script ) {
		_js = script;
	}

	public void setNoWrap( boolean wrap ) {
		_isNoWrap = wrap;
	}
}
